<div class="content-wrapper">
	<section class="content-header">
		<h1>
			【{$userInfo.name}】扩展功能
			<small>已开通的功能使用<span style='color: red;'>红色</span>标识</small>
		</h1>
		<ol class="breadcrumb">
			<li><a href="/admin"><i class="fa fa-dashboard"></i> 首页</a></li>
			<li class="active">账号管理</li>
			<li class="active"><a href="/admin/user/userList">用户列表</a></li>
			<li class="active">扩展功能设置</li>
		</ol>
	</section>
	<section class="content">
		<div class="box">
			<div class="box-header with-border">
				<input type="hidden" name="user_id" id="user_id" value="{$userInfo.id}" />				
			</div>
			<div class="box-body">
				<table class="table table-bordered">                            
                    <tbody>	                            	
                   		<tr>
                   			<td>
                   				<div class="accordion-group">
                   					<label style="width:250px;" class="position-relative">                            						
                   						<span class="lbl">
                   							<b>用户可访问系统</b>
                   						</span>
                   					</label>
                   				</div>
                   				<div class="accordion-inner" style="padding:9px 15px 9px 30px;">
                   					<foreach name="appList" item="app">
                   						<label  style="width:250px;" class="position-relative">
                   							<input type="checkbox" class="ace" name="app_ids[]" value="{$app.app_id}" <if condition="$app.is_checked eq 1">checked</if>>
                   							<span class="lbl" style="font-weight:normal;<if condition='$app.is_checked eq 1'>color:#FF0000;</if>" title="{$app.name}">{$app.name}</span>
                   						</label>
                   					</foreach>
                   				</div>
                   				<button class="btn btn-info btn-sm" type="button" id="save-user-app-btn">保存</button>
                   			</td>
                   		</tr>	                            	
                    </tbody>
                </table>
				<table class="table table-bordered">
					<tbody>
					<tr>
						<td>
							<div class="accordion-group">
								<label style="width:250px;" class="position-relative">
                   						<span class="lbl">
                   							<b>用户可管理部门</b>
                   						</span>
								</label>
							</div>
							<div class="accordion-inner" style="padding:9px 15px 9px 30px;">
								<foreach name="departmentList" item="department">
									<label  style="width:250px;" class="position-relative">
										<input type="checkbox" class="ace" name="department_ids[]" value="{$department.id}" <if condition="$department.is_checked eq 1">checked</if>>
										<span class="lbl" style="font-weight:normal;<if condition='$app.is_checked eq 1'>color:#FF0000;</if>" title="{$department.name}">{$department.name}</span>
									</label>
								</foreach>
							</div>
							<button class="btn btn-info btn-sm" type="button" id="save-user-department-btn">保存</button>
						</td>
					</tr>
					</tbody>
				</table>
			</div>			
		</div>
	</section>
</div>

<script type="text/javascript">
$(function(){
	//保存用户可访问系统
	$("#save-user-app-btn").click(function(){
		var user_id = $("#user_id").val();
		var appIdList = [];
		$('input[name="app_ids[]"]:checked').each(function(){
            var app_id = $(this).val();
            appIdList.push(app_id);
        });
		
		$.post('/admin/user/saveUserRelationApp', {user_id:user_id, app_ids:appIdList.join(',')}, function(data){
			if(data.Code == 999) {
				ArtDialogHlp.showInfo('提示', '操作成功', function(){
					window.location.reload();
				});
			} else {
				ArtDialogHlp.showInfo('提示', data.Msg);
			}
		}, 'json');
	});
    //保存用户可管理部门
    $("#save-user-department-btn").click(function(){
        var user_id = $("#user_id").val();
        var departmentIdList = [];
        $('input[name="department_ids[]"]:checked').each(function(){
            var department_id = $(this).val();
            departmentIdList.push(department_id);
        });

        $.post('/admin/user/saveUserRelationDepartment', {user_id:user_id, department_ids:departmentIdList.join(',')}, function(data){
            if(data.Code == 999) {
                ArtDialogHlp.showInfo('提示', '操作成功', function(){
                    window.location.reload();
                });
            } else {
                ArtDialogHlp.showInfo('提示', data.Msg);
            }
        }, 'json');
    });
});
</script>